import request from '@/utils/request'

// 认证相关API
export const login = (data) => {
  return request({
    url: '/auth/login',
    method: 'post',
    data
  })
}

export const getUserInfo = () => {
  return request({
    url: '/auth/user-info',
    method: 'get'
  })
}

export const logout = () => {
  return request({
    url: '/auth/logout',
    method: 'post'
  })
}

// 优惠券相关API
export const getCouponList = (params) => {
  return request({
    url: '/coupon/page',
    method: 'get',
    params
  })
}

export const createCoupon = (data) => {
  return request({
    url: '/coupon',
    method: 'post',
    data
  })
}

export const updateCoupon = (id, data) => {
  return request({
    url: `/coupon/${id}`,
    method: 'put',
    data
  })
}

export const deleteCoupon = (id) => {
  return request({
    url: `/coupon/${id}`,
    method: 'delete'
  })
}

export const publishCoupon = (id) => {
  return request({
    url: `/coupon/${id}/publish`,
    method: 'post'
  })
}

export const stopCoupon = (id) => {
  return request({
    url: `/coupon/${id}/stop`,
    method: 'post'
  })
}

export const getCouponDetail = (id) => {
  return request({
    url: `/coupon/${id}`,
    method: 'get'
  })
}

export const batchOperateCoupons = (data) => {
  return request({
    url: '/coupon/batch',
    method: 'post',
    data
  })
}

export const getCouponAnalysis = (id) => {
  return request({
    url: `/coupon/${id}/analysis`,
    method: 'get'
  })
}

// 用户相关API
export const getUserList = (params) => {
  return request({
    url: '/user/page',
    method: 'get',
    params
  })
}

export const getUserDetail = (id) => {
  return request({
    url: `/user/${id}`,
    method: 'get'
  })
}

export const getUserCoupons = (id, params) => {
  return request({
    url: `/user/${id}/coupons`,
    method: 'get',
    params
  })
}

// 统计相关API
export const getDashboardData = () => {
  return request({
    url: '/statistics/dashboard',
    method: 'get'
  })
}

export const getCouponStatistics = (params) => {
  return request({
    url: '/statistics/coupon',
    method: 'get',
    params
  })
}

export const getUserStatistics = (params) => {
  return request({
    url: '/statistics/user',
    method: 'get',
    params
  })
}

// AI相关API
export const getPersonalizedCoupons = (userId, limit = 10) => {
  return request({
    url: '/ai/personalized-coupons',
    method: 'get',
    params: { userId, limit }
  })
}

export const generateDynamicCoupon = (userId, baseCouponId) => {
  return request({
    url: '/ai/dynamic-coupon',
    method: 'post',
    data: { userId, baseCouponId }
  })
}

export const getUserProfile = (userId) => {
  return request({
    url: `/ai/user-profile/${userId}`,
    method: 'get'
  })
}

export const updateUserProfile = (userId, data) => {
  return request({
    url: `/ai/user-profile/${userId}`,
    method: 'put',
    data
  })
}
